/**
 * @file categories/math/matrix/cf1136c/main.cpp
 * @brief
 *每次转置的时候反对角线，以及与反对角线平行的所有直线上的元素都是不变的。
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/6 15:47:58
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 500;
int a[N][N], b[N][N];
vi aa[N * 2], bb[N * 2];

int main() {
  // High rating and good luck!
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> a[i][j];
      aa[i + j].push_back(a[i][j]);
    }
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      cin >> b[i][j];
      bb[i + j].push_back(b[i][j]);
    }
  bool ok = true;
  for (int i = 0; i < N * 2; ++i) {
    sort(aa[i].begin(), aa[i].end());
    sort(bb[i].begin(), bb[i].end());
    if (aa[i] != bb[i]) {
      ok = false;
      break;
    }
  }
  cout << (ok ? "YES\n" : "NO\n");
  return 0;
}
